package com.cy.pj.sys.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.sys.entity.SysRole;
import com.cy.pj.sys.service.SysRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/role")
public class SysRoleController {
    @Autowired
    private SysRoleService sysRoleService;

    //用于查询角色信息
    @RequestMapping("/doFindPageObjects")
    public JsonResult doFindPageObjects(String name,
                                        Integer pageCurrent){
        return new JsonResult(sysRoleService.findPageObjects(name,pageCurrent));
    }

    //用于删除角色相关信息
    @RequestMapping("/doDeleteObject")
    public JsonResult doDeleteObject(Integer id){
        sysRoleService.deleteObject(id);
        return new JsonResult("delete ok");
    }

    //用于保存角色信息
    @RequestMapping("/doSaveObject")
    public JsonResult doSaveObject(SysRole entity,
                                   Integer[] menuIds){
        sysRoleService.saveObject(entity, menuIds);
        return new JsonResult("save ok");
    }

    //根据id查询角色信息
    @RequestMapping("doFindObjectById")
    public JsonResult doFindObjectById(Integer id){
        return new JsonResult(sysRoleService.findObjectById(id));
    }

    //根据前端的数据,进行更新操作
    @RequestMapping("/doUpdateObject")
    public JsonResult doUpdateObject(SysRole entity, Integer[] menuIds){
        sysRoleService.updateObject(entity, menuIds);
        return new JsonResult("update ok");
    }

    //根据前端请求,查询角色id,name信息
    @RequestMapping("/doFindRoles")
    public JsonResult doFindRoles(){
        return new JsonResult(sysRoleService.findObject());
    }
}
